package com.example.jasonrpc.example;

import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;

/**
 * 基于RMI的RPC实现客户端
 */
public class RMIClient {
    public static void main(String[] args) {
        String serverIp = ConfigUtil.getServerIp("config");
        int serverPort = ConfigUtil.getServerPort("config");
        try {
            CalcService calcService = (CalcService) Naming.lookup("//"+serverIp+":"+serverPort+"/CalcService");
            int addRes = calcService.add(2, 3);
            System.out.println(addRes);
            int substract = calcService.substract(12, 3);
            System.out.println(substract);
        } catch (RemoteException | NotBoundException | MalformedURLException e) {
            e.printStackTrace();
        }
    }
}
